home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / The GIMP / gimp-2.6.8-i686-setup.exe / {app} / lib / gimp / 2.0 / plug-ins / palette-offset.py < prev    next >
Encoding:
Python Source  |  2009-12-15  |  2.3 KB  |  63 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #    This program is free software; you can redistribute it and/or modify
  4. #   it under the terms of the GNU General Public License as published by
  5. #   the Free Software Foundation; either version 2 of the License, or
  6. #   (at your option) any later version.
  7. #
  8. #   This program is distributed in the hope that it will be useful,
  9. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #   GNU General Public License for more details.
  12. #
  13. #   You should have received a copy of the GNU General Public License
  14. #   along with this program; if not, write to the Free Software
  15. #   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. from gimpfu import *
  18.  
  19. gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
  20.  
  21. def palette_offset(palette, amount):
  22.     #If palette is read only, work on a copy:
  23.     editable = pdb.gimp_palette_is_editable(palette)
  24.     if not editable:palette = pdb.gimp_palette_duplicate (palette)
  25.  
  26.     num_colors = pdb.gimp_palette_get_info (palette)
  27.  
  28.     tmp_entry_array = []
  29.     for i in xrange (num_colors):
  30.         tmp_entry_array.append  ((pdb.gimp_palette_entry_get_name (palette, i),
  31.                                   pdb.gimp_palette_entry_get_color (palette, i)))
  32.     for i in xrange (num_colors):
  33.         target_index = i + amount
  34.         if target_index >= num_colors:
  35.             target_index -= num_colors
  36.         elif target_index < 0:
  37.             target_index += num_colors
  38.         pdb.gimp_palette_entry_set_name (palette, target_index, tmp_entry_array[i][0])
  39.         pdb.gimp_palette_entry_set_color (palette, target_index, tmp_entry_array[i][1])
  40.     return palette
  41.  
  42.  
  43. register(
  44.     "python-fu-palette-offset",
  45.     N_("Offset the colors in a palette"),
  46.     "palette_offset (palette, amount) -> modified_palette",
  47.     "Joao S. O. Bueno Calligaris, Carol Spears",
  48.     "(c) Joao S. O. Bueno Calligaris",
  49.     "2004, 2006",
  50.     N_("_Offset Palette..."),
  51.     "",
  52.     [
  53.      (PF_PALETTE, "palette", _("Palette"), ""),
  54.      (PF_INT,     "amount",  _("Off_set"),  1),
  55.     ],
  56.     [(PF_PALETTE, "new-palette", "Result")],
  57.     palette_offset,
  58.     menu="<Palettes>",
  59.     domain=("gimp20-python", gimp.locale_directory)
  60.     )
  61.  
  62. main ()
  63.